import { Controller, Post, Sse, Body, Header } from '@nestjs/common';
import { Observable } from 'rxjs';
import { DeepseekService } from './deepseek.service';

@Controller('deepseek')
export class DeepseekController {
  constructor(private readonly deepseekService: DeepseekService) {}

  @Sse('/stream')
  @Header('Connection', 'keep-alive')
  @Header('Cache-Control', 'no-cache')
  @Header('Content-Type', 'text/event-stream')
  @Header('Access-Control-Allow-Origin', '*')
  stream(): Observable<MessageEvent> {
    return this.deepseekService.stream(); 
  }

  @Post('/question')
  addList(@Body() body: { question: string }) {
    const { question } = body;
    return this.deepseekService.answer(question);
  }

  @Post('/rag')
  rag(@Body() body: { question: string }) {
    const { question } = body;
    return this.deepseekService.rag(question);
  }

  @Post('/tools')
  async tools(@Body() body: { question: string }) {
    const { question } = body;
    const res = await this.deepseekService.tools(question);
    return res;
  }

  @Post('/add-rag-data')
  addRagData(@Body() body: { url: string }) {
    const { url } = body;
    return this.deepseekService.addRagData(url);
  }
}
